package com.frxuexi.park2212.payment

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.frxuexi.lib_base.base.BaseActivity
import com.frxuexi.lib_base.net.Const
import com.frxuexi.park2212.R
import com.frxuexi.park2212.databinding.ActivityMyBillBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/MyBillActivity")
@AndroidEntryPoint
class MyBillActivity : BaseActivity<ActivityMyBillBinding,PayViewModel>() {
    val billAdapter by lazy { BillAdapter() }
    override fun initData() {
        vm.getBills.observe(this){
            billAdapter.addData(it)
            billAdapter.notifyDataSetChanged()
        }
    }

    override fun initView() {
        binding.headBill.apply {
            headerBack.setOnClickListener {
                finish()
            }
            headerTitle.setText("账单详情")
            headerAdd.visibility=View.GONE
        }

        vm.getBills(SPUtils.getInstance().getInt(Const.UID))
        binding.rvBill.apply {
            adapter=billAdapter
            layoutManager=LinearLayoutManager(this@MyBillActivity)
        }

        billAdapter.setOnItemClickListener { adapter, view, position ->
            ARouter.getInstance().build("/app/BillDetailActivity").withString("bid",billAdapter.data.get(position).id.toString()).navigation()
        }
    }

}